//KY95牛客 Old Bill
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    int n;
    char x,y,z;
    while(scanf("%d %c %c %c",&n,&x,&y,&z)!=EOF)
    {
        int max=0;
        int k;
        char x1,x2;
        int flag = 0;
        for(int p=10000/n;n*p<=99999;p++)
        {
            char arr[5]={};
            sprintf(arr,"%d",n*p);
            if(arr[1]==x&&arr[2]==y&&arr[3]==z)
            {
                if(n*p>max)
                {
                    x1=arr[0];
                    x2=arr[4];
                    k=p;
                    flag = 1;
                }
            }
        }
        if(flag==1)
            printf("%c %c %d\n",x1,x2,k);
        else
            printf("0");
    }
    return 0;
}